import { sys } from 'cc';
import { _decorator } from 'cc';
import { Eventify } from 'cc';
import { System } from 'cc';
import { bdrm } from './ttScripts/ByteDanceRecorderManager';
import { wcm } from './wxScripts/WechatManager';
const { ccclass, property } = _decorator;

@ccclass('SDKRecorderManager')
export class SDKRecorderManager extends Eventify(System) {
    public static instance: SDKRecorderManager;

    get recording(): boolean {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                return bdrm.recording;
            //case sys.Platform.WECHAT_GAME:
            //return wcrm.recording;
            default:
                return false;

        }
    };

    get time(): number {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                return bdrm.time;
            //case sys.Platform.WECHAT_GAME:
            //return wcrm.time;
            default:
                return 0;
        }
    };

    get isError(): boolean {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                return bdrm.isError;
            //case sys.Platform.WECHAT_GAME:
            //return wcrm.isError;
            default:
                return false;
        }
    };
    registerSystem() {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                bdrm.registerSystem();
                break;
            // case sys.Platform.WECHAT_GAME:
            //     WechatRecorderManager.registerSystem();
            //     break;
            default:
                break;
        }
    }

    init() {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                bdrm.init();
                break;
            //case sys.Platform.WECHAT_GAME:
            //wcrm.init();
            //break;
            default:
                break;
        }
    }

    /**
     * 抖音录屏组件
     */
    public ByteDanceRecorderInit() {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                bdrm.ByteDanceRecorderInit();
                break;
            //case sys.Platform.WECHAT_GAME:
            //wcrm.ByteDanceRecorderInit();
            //break;
            default:
                break;
        }

    }

    //开始录屏
    public startRecoder(callback) {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                bdrm.startRecoder(callback);
                break;
            //case sys.Platform.WECHAT_GAME:
            //wcrm.startRecoder(callback);
            //break;
            default:
                callback(true);
                break;
        }

    }

    //停止录屏
    public stopRecoder(callback) {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                bdrm.stopRecoder(callback);
                break;
            //case sys.Platform.WECHAT_GAME:
            //wcrm.stopRecoder(callback);
            //break;
            default:
                callback(true);
                break;
        }

    }

    public pauseRecorder() {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                bdrm.pauseRecorder();
                break;
            //case sys.Platform.WECHAT_GAME:
            //wcrm.pauseRecorder();
            //break;
            default:
                break;
        }
    }

    public resumeRecorder() {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                bdrm.resumeRecorder();
                break;
            //case sys.Platform.WECHAT_GAME:
            //wcrm.resumeRecorder();
            //break;
            default:
                break;
        }
    }

    public share() {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                return bdrm.share();
            //case sys.Platform.WECHAT_GAME:
            //wcrm.share();
            //break;
            // case sys.Platform.WECHAT_GAME:
            //     return wcm.share();
            default:
                break;
        }
    }
}

globalThis.SDKRecorderManager = SDKRecorderManager;

export const sdkrm = SDKRecorderManager.instance = new SDKRecorderManager();